﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace JXT.PrimaryKey.Batman.Core.OAuth
{
    /// <summary>
    /// 腾讯OAuth认证基类
    /// </summary>
    public class TencentRestAuth : RestAuth
    {
        public TencentRestAuth(string appKey = null, string signatureKey = null, Func<IHttpClient> httpClientCreater = null) : base(appKey, signatureKey, httpClientCreater) { }

        public override string GetAuthorizeUri(Uri requestTokeUri, Uri authorizeUri, Uri callback, bool isEnforce = false)
        {
            if (String.IsNullOrEmpty(Context.Token) || String.IsNullOrEmpty(Context.TokenSecret) || isEnforce)
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters.Add("oauth_callback",UrlEncode(callback.ToString()));
                getRequestToken(requestTokeUri,parameters);
            }
            string url = String.Format("{0}?oauth_token={1}&oauth_callback={2}&display=page", authorizeUri, Context.Token, UrlEncode(callback.ToString()));
            return url;
        }
    }
}
